home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / performPolyProjectionArgList < prev    next >
Encoding:
Text File  |  2003-07-17  |  23.7 KB  |  662 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //  Alias|Wavefront Script File
  18. //  MODIFY THIS AT YOUR OWN RISK
  19. //
  20. //  Creation Date:  4 April 1997
  21. //
  22. //
  23. //  Description:
  24. //
  25. //
  26. //  Procedure Name:
  27. //      performPolyProjection
  28. //
  29. //  Description:
  30. //        adds a planar, cylindric or spheric projection to the selected polygon facets
  31. //         
  32. //  Input Arguments:
  33. //        $option : Whether to set the options to default values.
  34. //  Return Value:
  35. //        command string iff $option==2
  36. //
  37.  
  38. proc string argArrayAsString (string $args[])
  39. {
  40.     string $result = "{";
  41.     string $cast = "(string)";
  42.     for ($arg in $args) {
  43.         $result += ($cast + "\"" + $arg + "\"");
  44.         $cast = ", ";
  45.     }
  46.     return ($result + "}");
  47. }
  48.  
  49. proc setOptionVars (string $primitive, int $forceFactorySettings)
  50. {
  51.      // -icx/-imageCenterX  -icy/-imageCenterY 
  52.     if ($forceFactorySettings || !`optionVar -exists ("polyProjectionImageCenter" + $primitive)`)
  53.         optionVar -floatValue ("polyProjectionImageCenter" + $primitive) 0.5
  54.             -floatValueAppend ("polyProjectionImageCenter" + $primitive) 0.5;
  55.      
  56.     // -pcx/-projectionCenterX     -pcy/-projectionCenterY    -pcz/-projectionCenterZ
  57.     if ($forceFactorySettings || !`optionVar -exists ("polyProjectionCenter" + $primitive)`)
  58.         optionVar -floatValue ("polyProjectionCenter" + $primitive) 0.
  59.             -floatValueAppend ("polyProjectionCenter" + $primitive) 0.
  60.             -floatValueAppend ("polyProjectionCenter" + $primitive) 0.;
  61.  
  62.     // -rx/-rotateX  -ry/-rotateY  -rz/-rotateZ 
  63.     if ($forceFactorySettings || !`optionVar -exists ("polyProjectionRotate" + $primitive)`)
  64.         optionVar -floatValue ("polyProjectionRotate" + $primitive) 0.
  65.             -floatValueAppend ("polyProjectionRotate" + $primitive) 0.
  66.             -floatValueAppend ("polyProjectionRotate" + $primitive) 0.;
  67.  
  68.      // -psu/-projectionScaleU  -psv/-projectionScaleV 
  69.     float $fval1=180.0;    // [0:360] theta range of spherical coordinate system
  70.     float $fval2=90.0;    // [0:180] phi range of spherical coordinate system
  71.     if ($primitive == "Planar") {
  72.         $fval1=1.0;
  73.         $fval2=1.0;
  74.     } else if ($primitive == "Cylindrical") {
  75.         $fval2=1.0;        // Project using a cylinder of height 1.
  76.     }
  77.     if ($forceFactorySettings || !`optionVar -exists ("polyProjectionScaleU" + $primitive)`) 
  78.         optionVar   -floatValue ("polyProjectionScaleU" + $primitive) $fval1;
  79.     if ($forceFactorySettings || !`optionVar -exists ("polyProjectionScaleV" + $primitive)`) 
  80.         optionVar   -floatValue ("polyProjectionScaleV" + $primitive) $fval2;
  81.     
  82.     if ($forceFactorySettings || !`optionVar -exists ("polyProjectionSmartFit" + $primitive)`) {
  83.         optionVar -intValue ("polyProjectionSmartFit" + $primitive) 1;
  84.     }
  85.  
  86.     if ($forceFactorySettings || !`optionVar -exists ("polyProjectionFitToBoxOrPlane" + $primitive)`) {
  87.         optionVar -intValue ("polyProjectionFitToBoxOrPlane" + $primitive) 2;
  88.     }
  89.  
  90.     if ($forceFactorySettings || !`optionVar -exists ("polyProjectionMappingDirection" + $primitive)`) {
  91.         optionVar -intValue ("polyProjectionMappingDirection" + $primitive) 3;
  92.     }
  93.  
  94.     if ($forceFactorySettings || !`optionVar -exists ("polyProjectionInsertionPoint" + $primitive)`) {
  95.         optionVar -intValue ("polyProjectionInsertionPoint" + $primitive) 1;
  96.     }
  97.  
  98.     // -isu/-imageScaleU  -isv/-imageScaleV 
  99.     if ($forceFactorySettings || !`optionVar -exists ("polyProjectionImageScale" + $primitive)`)
  100.         optionVar -floatValue ("polyProjectionImageScale" + $primitive) 1.
  101.             -floatValueAppend ("polyProjectionImageScale" + $primitive) 1.;
  102.  
  103.     //  -ra/-rotationAngle 
  104.     if ($forceFactorySettings || !`optionVar -exists ("polyProjectionRotationAngle" + $primitive)`)
  105.         optionVar -floatValue ("polyProjectionRotationAngle" + $primitive) 0.;
  106.  
  107.     if ($primitive == "Planar")
  108.         if ($forceFactorySettings || !`optionVar -exists ("polyProjectionSquareImage" + $primitive)`)
  109.             optionVar -intValue ("polyProjectionSquareImage" + $primitive) 0;
  110.  
  111.     // -cm/-createMap
  112.     if ($forceFactorySettings || !`optionVar -exists ("polyProjectionCreateMap" + $primitive)`)
  113.         optionVar -intValue ("polyProjectionCreateMap" + $primitive) 0;        
  114.  
  115.     // -uvs/-uvSetName
  116.     if ($forceFactorySettings || !`optionVar -exists ("polyProjectionUvSetName" + $primitive)`)
  117.         optionVar -stringValue ("polyProjectionUvSetName" + $primitive) "uvSet1";        
  118. }
  119.  
  120. global proc performPolyProjectionSetup (string $primitive, string $parent, int $forceFactorySettings)
  121. {
  122.     setOptionVars($primitive, $forceFactorySettings);
  123.     setParent $parent;
  124.     float $vals[];
  125.     float $val;
  126.  
  127.     $vals = `optionVar -query ("polyProjectionImageCenter" + $primitive)`;
  128.      floatFieldGrp -edit -value1 $vals[0] -value2 $vals[1] polyProjectionImageCenter;
  129.  
  130.     $vals = `optionVar -query ("polyProjectionRotate" + $primitive)`;
  131.      floatFieldGrp -edit -value1 $vals[0] -value2 $vals[1] -value3 $vals[2] polyProjectionRotate;
  132.  
  133.     $vals = `optionVar -query ("polyProjectionCenter" + $primitive)`;
  134.      floatFieldGrp -edit -value1 $vals[0] -value2 $vals[1] -value3 $vals[2] polyProjectionCenter;
  135.  
  136.         $val = `optionVar -query ("polyProjectionScaleU" + $primitive)`;
  137.          floatSliderGrp -edit -value $val polyProjectionScaleU;
  138.         $val = `optionVar -query ("polyProjectionScaleV" + $primitive)`;
  139.          floatSliderGrp -edit -value $val polyProjectionScaleV;
  140.  
  141.     checkBoxGrp -edit -value1
  142.         `optionVar -q ("polyProjectionSmartFit" + $primitive)`
  143.             polyProjectionSmartFit;
  144.     
  145.     checkBoxGrp -edit -value1
  146.         `optionVar -q ("polyProjectionInsertionPoint" + $primitive)`
  147.             polyProjectionInsertionPoint;
  148.     
  149.     if ($primitive == "Planar") {
  150.         radioButtonGrp -edit -select
  151.             `optionVar -q ("polyProjectionFitToBoxOrPlane" + $primitive)`
  152.             polyProjectionFitToBoxOrPlane;
  153.     
  154.         radioButtonGrp -edit -select 
  155.             `optionVar -q ("polyProjectionMappingDirection" + $primitive)`
  156.             polyProjectionMappingDirection;
  157.     }
  158.     
  159.     if (`checkBoxGrp -query -value1 polyProjectionSmartFit`) 
  160.             enableSmartFit $primitive;    
  161.     else     disableSmartFit $primitive;
  162.  
  163.     $vals = `optionVar -query ("polyProjectionImageScale" + $primitive)`;
  164.      floatFieldGrp -edit -value1 $vals[0] -value2 $vals[1] polyProjectionImageScale;
  165.  
  166.     $val=`optionVar -query ("polyProjectionRotationAngle" + $primitive)`;
  167.      floatSliderGrp -edit -value $val polyProjectionRotationAngle;
  168.     
  169.     if ($primitive == "Planar")
  170.         checkBoxGrp -edit -value1 
  171.             `optionVar -q ("polyProjectionSquareImage" + $primitive)`
  172.                 polyProjectionSquareImage;
  173.  
  174.     $val = `optionVar -q ("polyProjectionCreateMap" + $primitive)`;
  175.     checkBoxGrp -edit -value1 $val polyProjectionCreateMap;
  176.     if ($val == 1)
  177.         disable -v false polyProjectionUvSetName;
  178.     else
  179.         disable -v true polyProjectionUvSetName;
  180.     textFieldGrp -edit -tx 
  181.         `optionVar -q ("polyProjectionUvSetName" + $primitive)`        
  182.         polyProjectionUvSetName;
  183. }
  184.  
  185. global proc performPolyProjectionCallback (string $primitive, string $args[], string $uvSetName, string $parent, int $doIt)
  186. {
  187.     setParent $parent;
  188.     
  189.     optionVar -floatValue ("polyProjectionImageCenter" + $primitive)
  190.         `floatFieldGrp -query -value1 polyProjectionImageCenter`
  191.         -floatValueAppend ("polyProjectionImageCenter" + $primitive)
  192.         `floatFieldGrp -query -value2 polyProjectionImageCenter`;
  193.     
  194.     optionVar -floatValue ("polyProjectionCenter" + $primitive)
  195.         `floatFieldGrp -query -value1 polyProjectionCenter`
  196.         -floatValueAppend ("polyProjectionCenter" + $primitive)
  197.         `floatFieldGrp -query -value2 polyProjectionCenter`
  198.         -floatValueAppend ("polyProjectionCenter" + $primitive)
  199.         `floatFieldGrp -query -value3 polyProjectionCenter`;
  200.         
  201.     optionVar -floatValue ("polyProjectionRotate" + $primitive)
  202.         `floatFieldGrp -query -value1 polyProjectionRotate`
  203.         -floatValueAppend ("polyProjectionRotate" + $primitive)
  204.         `floatFieldGrp -query -value2 polyProjectionRotate`
  205.         -floatValueAppend ("polyProjectionRotate" + $primitive)
  206.         `floatFieldGrp -query -value3 polyProjectionRotate`;
  207.         
  208.         optionVar -floatValue ("polyProjectionScaleU" + $primitive)
  209.             `floatSliderGrp -query -value polyProjectionScaleU`;
  210.         optionVar -floatValue ("polyProjectionScaleV" + $primitive)
  211.             `floatSliderGrp -query -value polyProjectionScaleV`;
  212.     
  213.     optionVar -intValue ("polyProjectionSmartFit" + $primitive)
  214.         `checkBoxGrp -query -value1 polyProjectionSmartFit`;
  215.  
  216.     if (`checkBoxGrp -query -value1 polyProjectionSmartFit`) 
  217.             enableSmartFit $primitive;    
  218.     else     disableSmartFit $primitive;
  219.  
  220.     if ($primitive == "Planar") {
  221.         optionVar -intValue ("polyProjectionFitToBoxOrPlane" + $primitive)
  222.             `radioButtonGrp -query -select polyProjectionFitToBoxOrPlane`;
  223.  
  224.         optionVar -intValue ("polyProjectionMappingDirection" + $primitive)
  225.             `radioButtonGrp -query -select polyProjectionMappingDirection`;
  226.     }
  227.  
  228.     optionVar -intValue ("polyProjectionInsertionPoint" + $primitive)
  229.         `checkBoxGrp -query -value1 polyProjectionInsertionPoint`;
  230.  
  231.     optionVar -floatValue ("polyProjectionImageScale" + $primitive)
  232.         `floatFieldGrp -query -value1 polyProjectionImageScale`
  233.         -floatValueAppend ("polyProjectionImageScale" + $primitive)
  234.         `floatFieldGrp -query -value2 polyProjectionImageScale`;
  235.     
  236.     optionVar -floatValue ("polyProjectionRotationAngle" + $primitive)
  237.         `floatSliderGrp -query -value polyProjectionRotationAngle`;
  238.         
  239.     if ($primitive == "Planar")
  240.         optionVar -intValue ("polyProjectionSquareImage" + $primitive)
  241.             `checkBoxGrp -query -value1 polyProjectionSquareImage`;
  242.  
  243.     optionVar -intValue ("polyProjectionCreateMap" + $primitive)
  244.          `checkBoxGrp -query -value1 polyProjectionCreateMap`;
  245.     optionVar -stringValue ("polyProjectionUvSetName" + $primitive)
  246.          `textFieldGrp -query -tx polyProjectionUvSetName`;
  247.  
  248.     if ($doIt) {
  249.         $args[0] = "0";
  250.         performPolyProjectionArgList 1 $args $uvSetName;
  251.         string $tmpCmd = "performPolyProjection \"" + $primitive + "\" 0";
  252.         string $tmpCmdLabel = "PolyProjection";
  253.         if ($primitive == "Planar") $tmpCmdLabel = "PolyPlanarProjection";
  254.         else if ($primitive == "Cylindrical") $tmpCmdLabel = "PolyCylindricalProjection";
  255.         else if ($primitive == "Spherical") $tmpCmdLabel = "PolySphericalProjection";
  256.         addToRecentCommandQueue $tmpCmd $tmpCmdLabel;
  257.     }
  258. }
  259.  
  260. global proc disableSmartFit(string $primitive)
  261. {
  262.     enableProjectionTransformation($primitive);
  263.     if ($primitive == "Planar")     {    
  264.         disable polyProjectionMappingDirection;
  265.         disable polyProjectionFitToBoxOrPlane;
  266.         disable polyProjectionSquareImage;
  267.     }
  268. }
  269.  
  270. global proc enableSmartFit(string $primitive)
  271. {
  272.     disableProjectionTransformation($primitive);
  273.     if ($primitive == "Planar")    {
  274.         disable -v false polyProjectionFitToBoxOrPlane;
  275.         disable -v false polyProjectionSquareImage;
  276.     }
  277.  
  278.     if ($primitive != "Planar")    return;
  279.  
  280.     int $res = `radioButtonGrp -query -select polyProjectionFitToBoxOrPlane`;
  281.     if ($res == 2)
  282.             disable -v false polyProjectionMappingDirection;
  283.     else     disable polyProjectionMappingDirection;
  284. }
  285.  
  286. global proc disableProjectionTransformation(string $primitive)
  287. {
  288.     disable polyProjectionCenter;
  289.     disable polyProjectionRotate;
  290.     disable polyProjectionScaleU;
  291.     disable polyProjectionScaleV;
  292.     return;
  293. }
  294.  
  295. global proc enableProjectionTransformation(string $primitive)
  296. {
  297.     disable -v false polyProjectionCenter;
  298.     disable -v false polyProjectionRotate;
  299.     disable -v false polyProjectionScaleU;
  300.     disable -v false polyProjectionScaleV;
  301.     return;
  302. }
  303.  
  304. global proc enableMappingDirection()
  305. {
  306.     disable -v false polyProjectionMappingDirection;
  307. }
  308.  
  309. global proc enableFitToBoxOrPlane()
  310. {
  311.     disable -v false polyProjectionFitToBoxOrPlane;
  312. }
  313.  
  314. proc polyProjectionOptions (string $primitive, string $args[], string $uvSetName)
  315. {
  316.     string $layout = getOptionBox();
  317.     setParent $layout;
  318.     setUITemplate -pushTemplate DefaultTemplate;
  319.     waitCursor -state 1;
  320.     tabLayout -scr true -tv false;
  321.     
  322.     string $parent = `columnLayout -adjustableColumn 1`;
  323.  
  324.     string $commandName = "performPolyProjection";
  325.     string $callback = ($commandName + "Callback " + $primitive + " " + argArrayAsString ($args) + " \"" + $uvSetName + "\" " + $parent + " ");
  326.     string $setup = ($commandName + "Setup " + $primitive + " " + $parent + " ");
  327.     
  328.     floatFieldGrp -label "Projection Center" -numberOfFields 3 polyProjectionCenter;
  329.     floatFieldGrp -label "Projection Rotation" -numberOfFields 3 polyProjectionRotate;
  330.  
  331.     if ($primitive == "Planar") {
  332.         floatSliderGrp -label "Projection Width" -min 0.0 -max 100.0 
  333.                             polyProjectionScaleU;
  334.         floatSliderGrp -label "Projection Height" -min 0.0 -max 100.0 
  335.                             polyProjectionScaleV;
  336.     } else if ($primitive == "Cylindrical") {
  337.         floatSliderGrp -label "Projection Horizontal Sweep" -min 0.0 -max 360.0 
  338.                             polyProjectionScaleU;
  339.         floatSliderGrp -label "Projection Height" polyProjectionScaleV;
  340.     } else {
  341.         // spherical
  342.         floatSliderGrp -label "Projection Horizontal Sweep" -min 0.0 -max 360.0 
  343.                             polyProjectionScaleU;
  344.         floatSliderGrp -label "Projection Vertical Sweep" -min 0.0 -max 180.0 
  345.                             polyProjectionScaleV;
  346.     }
  347.  
  348.     if ($primitive == "Planar")        
  349.         checkBoxGrp -label1 "Keep Image Ratio (Maintain Uniform Width/Height)" 
  350.         polyProjectionSquareImage;
  351.  
  352.     separator;
  353.  
  354.     checkBoxGrp    -label "Smart Fit" -label1 "Automatically Fit the Projection Manipulator"
  355.                 -onc ("enableSmartFit " + $primitive)
  356.                 -ofc ("disableSmartFit " + $primitive)
  357.                 polyProjectionSmartFit;
  358.  
  359.     if ($primitive == "Planar") {
  360.         radioButtonGrp -nrb 2 -label1 "Fit to Best Plane" -label2 "Fit to Bounding Box"
  361.                     -on1 ("disable polyProjectionMappingDirection")
  362.                     -of1 ("enableMappingDirection")
  363.                     polyProjectionFitToBoxOrPlane;
  364.  
  365.         radioButtonGrp -nrb 4 -label "Mapping Direction"
  366.                         -label1 "X Axis" -label2 "Y Axis" -label3 "Z Axis" -label4 "Camera"
  367.                         polyProjectionMappingDirection;
  368.     }
  369.  
  370.     checkBoxGrp -label1 "Insert Before Deformers" polyProjectionInsertionPoint;
  371.  
  372.     separator;
  373.  
  374.     floatFieldGrp -label "Image Center" -numberOfFields 2 polyProjectionImageCenter;
  375.     floatSliderGrp -label "Image Rotation" -min 0.0 -max 360.0 polyProjectionRotationAngle;    
  376.     floatFieldGrp -label "Image Scale" -numberOfFields 2 polyProjectionImageScale;
  377.  
  378.     separator;
  379.  
  380.     checkBoxGrp -label1 "Create New UV Set" 
  381.         -on1 ("disable -v false polyProjectionUvSetName")
  382.         -of1 ("disable -v true polyProjectionUvSetName")
  383.         polyProjectionCreateMap;
  384.     textFieldGrp -label "UV Set Name: " polyProjectionUvSetName;
  385.     
  386.     waitCursor -state 0;
  387.     setUITemplate -popTemplate;
  388.        
  389.     string $applyBtn = getOptionBoxApplyBtn();
  390.     button -edit -label "Project"
  391.            -command ($callback + 1)
  392.         $applyBtn;
  393.     string $saveBtn = getOptionBoxSaveBtn();
  394.     button -edit 
  395.         -command ($callback + 0 + "; hideOptionBox")
  396.         $saveBtn;
  397.     string $resetBtn = getOptionBoxResetBtn();
  398.     button -edit 
  399.         -command ($setup + 1)
  400.         $resetBtn;
  401.              
  402.     setOptionBoxTitle("Polygon " + $primitive + " Projection Options");
  403.  
  404.     if ($primitive == "Planar") {
  405.         setOptionBoxHelpTag( "PlanarMapping" );
  406.     } else if ($primitive == "Cylindrical") {
  407.         setOptionBoxHelpTag( "CylindricalMapping" );
  408.     } else if ($primitive == "Spherical") {
  409.         setOptionBoxHelpTag( "SphericalMapping" );
  410.     }
  411.  
  412.     eval (($setup + 0));
  413.     showOptionBox();
  414. }
  415.  
  416. proc string setCurrentCmd(string $primitive, int $forceCreate, string $uvSetName)
  417. {
  418.     int $createNewMap =    `optionVar -q ("polyProjectionCreateMap" + $primitive)`;
  419.     string $setCurrent = "";
  420.     if ($createNewMap || $forceCreate)
  421.         $setCurrent = "polyUVSet -luv";
  422.     return $setCurrent;
  423. }
  424.  
  425. proc string assembleCmd(string $primitive, int $forceCreate, string $uvSetName)
  426. {
  427.     setOptionVars ($primitive, false);
  428.  
  429.     int $doHistory = `constructionHistory -q -toggle`;
  430.     float $ic[]=`optionVar -query ("polyProjectionImageCenter" + $primitive)`;
  431.     float $ir=`optionVar -query ("polyProjectionRotationAngle" + $primitive)`;
  432.     float $is[]=`optionVar -query ("polyProjectionImageScale" + $primitive)`;
  433.  
  434.     int $createNewMap =    `optionVar -q ("polyProjectionCreateMap" + $primitive)`;
  435.     string $mapname = `optionVar -q ("polyProjectionUvSetName" + $primitive)`;
  436.  
  437.  
  438. //    string $cmd=("poly" + $primitive + "Projection" + " -ch " + $doHistory);
  439.     string $cmd=("polyProjection -ch " + $doHistory + " -type " + $primitive);
  440.     if (`optionVar -query ("polyProjectionInsertionPoint" + $primitive)`)
  441.         $cmd+=(" -ibd on");
  442.     else $cmd+=(" -ibd off");
  443.  
  444.     $cmd+=(" -icx " + $ic[0] + " -icy " + $ic[1] +
  445.             " -ra " + $ir + 
  446.             " -isu " + $is[0] + " -isv " + $is[1]);
  447.  
  448.     if ($createNewMap || $forceCreate)
  449.     {
  450.         if ($forceCreate) $mapname = $uvSetName;
  451.         if (size($mapname))
  452.         {
  453.             $cmd = $cmd + (" -cm on -uvSetName " + $mapname);
  454.         }
  455.     }
  456.  
  457.     int $fitToBoundingBox = 0, $fitToBestPlane = 0;
  458.  
  459.     if (`optionVar -q ("polyProjectionSmartFit" + $primitive)`) {
  460.         if ($primitive == "Planar") {
  461.             if (`optionVar -query ("polyProjectionSquareImage" + $primitive)`)
  462.                 $cmd+=(" -kir ");
  463.         } else {
  464.             $cmd+=(" -sf on ");
  465.             return $cmd;
  466.         }
  467.  
  468.         int $result=`optionVar -q ("polyProjectionFitToBoxOrPlane" + $primitive)`;
  469.         if ($result == 1) return ($cmd + " -md b");        //Best Plane
  470.         else if ($result == 2) {            //Bounding Box with direction
  471.             int $mdir = `optionVar -q ("polyProjectionMappingDirection" + $primitive)`;
  472.             switch ($mdir) {
  473.                 case 1: return ($cmd + " -md x ");
  474.                 case 2: return ($cmd + " -md y ");
  475.                 case 3: return ($cmd + " -md z ");
  476.                 case 4: return ($cmd + " -md c ");
  477.             }
  478.         }
  479.         //Should never reach this line
  480.     } else {
  481.         if ($primitive != "Planar") {
  482.             $cmd+=(" -sf off ");
  483.         }
  484.     }
  485.  
  486.     // Well, No smart fittings here.  Just pass those values to the command
  487.  
  488.     float $pc[]=`optionVar -query ("polyProjectionCenter" + $primitive)`;
  489.     float $pr[]=`optionVar -query ("polyProjectionRotate" + $primitive)`;
  490.  
  491.     $cmd+=(" -pcx " + $pc[0] + " -pcy " + $pc[1] + " -pcz " + $pc[2] + 
  492.            " -rx " + $pr[0] + " -ry  " + $pr[1] + " -rz  " + $pr[2]);
  493.  
  494.     float $valU=`optionVar -query ("polyProjectionScaleU" + $primitive)`;
  495.        float $valV=`optionVar -query ("polyProjectionScaleV" + $primitive)`;
  496.     $cmd += (" -psu " + $valU + " -psv " + $valV);
  497.  
  498.     return $cmd;    
  499. }
  500.  
  501. proc string createCurrentShader ()
  502. {
  503.     global string $polyTextureColorShader;
  504.     string $shader;
  505.     string $shaderType="lambert";
  506.     string $textureName="checker";
  507.     if (`optionVar -q polyCreateShaderWithMapping` == 0) 
  508.         return "";
  509.     string $shader=`evalEcho "sets -n texturedFacets -em -r true -nss true"`;
  510.     if ($shader != "") {
  511.         evalEcho ("partition -e -addSet renderPartition " + $shader);
  512.         string $shad[];
  513.         if ($polyTextureColorShader != "")
  514.             $shad=`ls -showType $polyTextureColorShader`;
  515.         if ($polyTextureColorShader == "" || size($shad) == 0) {
  516.             string $texture[]=`ls -showType defaultPolygonTexture`;
  517.             if (size($texture) == 0)
  518.                 $texture[0]=`evalEcho ("shadingNode -asTexture " 
  519.                         + $textureName + " -n defaultPolygonTexture")`;            
  520.             $polyTextureColorShader=`evalEcho ("shadingNode -asShader " 
  521.                         + $shaderType + " -n defaultPolygonShader")`;
  522.             evalEcho ("connectAttr " + $texture[0] + ".outColor " 
  523.                     + $polyTextureColorShader + ".color");
  524.             // creating a node selects it: we don't want that...
  525.             select -d $texture[0] $polyTextureColorShader;
  526.         }
  527.         $shad=`ls -showType $polyTextureColorShader`;
  528.         if ($polyTextureColorShader != "" && size($shad) != 0)
  529.             evalEcho ("connectAttr -f " + $polyTextureColorShader + ".outColor " 
  530.                                 + $shader + ".surfaceShader");
  531.         else warning "Could not create the default polygons shader";
  532.     } else warning "Could not create a new set to hold the faces.";
  533.     return $shader;
  534. }
  535.  
  536.  
  537. proc concatArray(string $res[], string $to_add[])
  538. {
  539.     for($i in $to_add)
  540.         $res[size($res)] = $i;
  541. }
  542.  
  543. global proc string performPolyProjectionArgList 
  544.     (string $version, string $args[], string $uvSetName)
  545. //
  546. //    Input Arguments:
  547. //    $version: The version of this option box.  Used to know how to 
  548. //    interpret the $args array.
  549. //        "1" : $action, $primitive, $selectCmd
  550. //
  551. //    $args
  552. //    Version 1
  553. //    [0]        $action        0 : Execute the command.
  554. //                        1 : Show the option box dialog.
  555. //                        2 : Return the command.
  556. //    [1]        $primitive    The type of primitive to create
  557. //    [2]        $selectCmd    The command to issue to determine which objects
  558. //                            to affect
  559. //    [3]        $forceCreate    Whether or not to force creation of a new UV set
  560. //
  561. //    $uvSetName: The requested name for a new uv set
  562. //
  563. //  Return Value:
  564. //      The string to execute for this option box.
  565. //
  566. {
  567.     int        $versionNum                = $version;
  568.  
  569.     int        $action                    = $args[0];
  570.     string    $primitive                = $args[1];
  571.     string    $selectCmd                = $args[2];
  572.     int        $forceCreate            = $args[3];
  573.  
  574.     string $cmd="";
  575.     string $lbl;
  576.     string $sel[], $preFilteredSel[];
  577.     switch ($action) {
  578.     case 0:
  579.         string $objects[] = `eval ($selectCmd)`;
  580.         $sel=`filterExpand -ex false -sm 34 $objects`;
  581.         if (size($sel) > 0) {
  582.             // If selection contains faces, use them
  583.             $preFilteredSel=$sel;
  584.         } else {
  585.             // Try to convert the selection to faces (if the flag is turned on)
  586.             $preFilteredSel=`polyCheckSelection ("poly"+$primitive+"Projection") f`;
  587.             string $expSel[];
  588.             $expSel = `filterExpand -ex false -sm 34 `;
  589.             if (size($expSel) <= 0) {
  590.                 // If the flag is turned off, suggest to turn it on,
  591.                 warning("polyProjection works only on polygonal faces;" +
  592.                     " Try turning Polygons->ToolOptions->ConvertSelection On.");
  593.                 return $cmd;
  594.             }
  595.         }
  596.  
  597.         if (size($preFilteredSel) != 0) {
  598.             setOptionVars($primitive, false);
  599.             int $index=0;
  600.             string $oldnodes[]=`ls -sl -dep`;
  601.             if (size($oldnodes) > 0)
  602.                 select -d $oldnodes;
  603.  
  604.             string $totalSel[];
  605.  
  606.             // what is selected ?
  607.             concatArray($totalSel, `ls -sl`);
  608.  
  609.             // Do projections.
  610.  
  611.             string $cmd=`assembleCmd $primitive $forceCreate $uvSetName`;
  612.             for ($i = 0; $i < size($preFilteredSel); $i++)
  613.                 $cmd += (" " + $preFilteredSel[$i]);
  614.  
  615.             string $res[];
  616.             $res=`evalEcho $cmd`;
  617.             // append $res (nodes) to $totalSel
  618.             concatArray($totalSel, $res);
  619.  
  620.             // Set current
  621.             string $setCurrent = `setCurrentCmd $primitive $forceCreate $uvSetName`;
  622.             if (size($setCurrent))
  623.             {
  624.                 for ($i = 0; $i < size($preFilteredSel); $i++)
  625.                     $setCurrent += (" " + $preFilteredSel[$i]);
  626.                 evalEcho $setCurrent;
  627.             }
  628.  
  629.             string $shader=`createCurrentShader`;
  630.             // Update shader's set.
  631.             if( $shader != "") {
  632.                 $cmd=("sets -e -fe " + $shader);
  633.                 int $i;
  634.                 for($i=0; $i < size($preFilteredSel); $i++)
  635.                     $cmd=($cmd + " " + $preFilteredSel[$i]);
  636.                 evalEcho $cmd;
  637.             }
  638.  
  639.             // Set selection
  640.             evalEcho `select -r $totalSel`;
  641.  
  642.             // clear $sel;
  643.             global string $polyLastTool;
  644.             $polyLastTool="";
  645.             setToolTo ShowManips;
  646.  
  647.         } else warning("PolyProjection works on polygonal faces.  Select them and invoke the command."); 
  648.         
  649.         break;
  650.  
  651.     case 1: polyProjectionOptions $primitive $args $uvSetName; break;
  652.     case 2: $cmd=`assembleCmd $primitive $forceCreate $uvSetName`;    
  653.       string $setCurrent = `setCurrentCmd $primitive $forceCreate $uvSetName`;
  654.       $cmd += ("; " + $setCurrent);
  655.       break;
  656.     default:
  657.         // this is useless: setOptionVars(false);
  658.         $cmd = ("performPolyProjection " + $primitive + " 0");
  659.     }
  660.     return $cmd;
  661. }
  662.